package com.cx.mall.demo.service.impl;

import com.alibaba.fastjson2.JSON;
import com.cx.mall.api.user.UserReceiveAddressFeign;
import com.cx.mall.common.utils.ResponseEnum;
import com.cx.mall.common.utils.ResponseVO;
import com.cx.mall.demo.model.UserReceiveAddress;
import com.cx.mall.demo.service.IUserReceiveAddressFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserReceiveAddressFeignServiceImpl implements IUserReceiveAddressFeignService {

    @Autowired
    private UserReceiveAddressFeign userReceiveAddressFeign;
    @Override
    public List<UserReceiveAddress> listById(Long userId,String auth) {
        ResponseVO result = userReceiveAddressFeign.listById(userId,auth);
        if(result.getCode() != ResponseEnum.SUCCESS.getCode()){
            throw new RuntimeException(result.getMessage());
        }
        List<UserReceiveAddress> list =
                JSON.parseArray(JSON.toJSONString(result.getData()), UserReceiveAddress.class);
        return list;
    }

    @Override
    public void save(com.cx.mall.common.model.user.UserReceiveAddress userReceiveAddress) {
        ResponseVO result = userReceiveAddressFeign.save(userReceiveAddress);
        if(result.getCode() != ResponseEnum.SUCCESS.getCode()){
            throw new RuntimeException(result.getMessage());
        }
    }

}
